/********
Accenture IDC
24th Nov 2011
Fulfillment item
Requirement Description: Create a reminder when the "ATTUID" on user and "Content last modified by" field on Fulfillment Item object are unequal.  
**/

trigger FulfillmentItemUpdateReminders  on Fullfilment_Item__c (before update,after update) 
{
    Set<id> userID = new Set<ID>();
    List<Fullfilment_Item__c> FIList = new list<Fullfilment_Item__c>();
    Map<ID,String> attUIDMap = new Map<ID,String>();

    for(Fullfilment_Item__c fi : Trigger.new)
    {
        userID.add(fi.ownerID);
    }


        //List<User> userList= [SELECT ID, ATTUID__c FROM User where IsActive=true and ATTUID__c!=null];        
        
        for(User userInfo:[SELECT ID, ATTUID__c FROM User where IsActive=true and ATTUID__c!=null and id in :userID])
        {
            attUIDMap.put(userInfo.ID,userInfo.ATTUID__c);        
        }
        for(Fullfilment_Item__c FI : trigger.new)
        {                   
         if(FI.Content_Last_Modified_By__c != null && FI.Content_Version__c  != null  
                  && (FI.Content_Last_Modified_By__c != Trigger.oldMap.get(FI.ID).Content_Last_Modified_By__c 
                  || FI.Content_Version__c != Trigger.oldMap.get(FI.ID).Content_Version__c)                        
                  && FI.Content_Last_Modified_By__c != attUIDMap.get(FI.OwnerID)
                  && String.valueOf(FI.OwnerId).startsWith(IfullfillTextConstant.USER_ID_STARTS_WITH))                      
   
            {
                FIList.add(FI);
            }
        }
        
        System.debug('FIList value '+FIList);
        iFulfillCreateTask.reminderevents(FIList);

}